package com.ch.贪心;

/**
 * @author chenhong
 * @version 1.0.0
 * @ClassName N135.java
 * @Description TODO
 * @createTime 2021年04月03日 20:53:00
 */
public class N135 {
    public static void main(String[] args) {
        Solution135 solution = new Solution135();
        int []a = {1,3,2,2,1};
        solution.candy(a);
    }
}

class Solution135 {
    public int candy(int[] ratings) {
        int[] ret = new int[ratings.length];
        int len = ratings.length;
        ret[0] = 1;
        for (int i = 1; i < len; i++) {
            if (ratings[i] > ratings[i - 1]) {
                ret[i] = ret[i - 1] + 1;
            } else {
                ret[i] = 1;
            }
        }
        int count = ret[len - 1];
        for (int j = len - 2; j>=0;j-- ){
            count += ret[j];
            if(ratings[j] > ratings[j + 1]){
                count++;
            }
        }
        return count;

    }
}